//首页
function index() {
    let mockData = Mock.mock({
        "headLeftList|5": [{
            "title": "@ctitle(3,6)",
            "linklist|3-9": [{
                "con": "@ctitle(2,4)",
                "href": "#"
            }],
        }],
        "bannerList|6": [{
            "img": "@image('960x380',@color)",
            "href": "#",
        }],
        "headimglist|4": [{
            "img": "@image('240x260',@color)",
            "href": "#"
        }],
        //热门品牌
        "hotimg": "@image(480x300,@color)",
        "hotpplist|3": [{
            "title": "@ctitle(4,4)",
            "imglist|16": [{
                "img": "@image(180x64,@color)",
                "href": "#"
            }]
        }],
        //特价秒杀
        "miaolist|5": [{
            "day|1-5": 1,
            "banner": "@image(240x290,@color)",
            "icon": "@image(180x64,@color)",
            "text": "@ctitle(5,12)",
            "href": "#"
        }],
        //品质时尚
        "pinzhi": {
            "taglist|8-10": [{
                "text": "@ctitle(2,4)",
                "href": "#"
            }],
            "iconlist|15": [{
                "img": "@image(180x64,@color)",
                "href": "#"
            }],
            "collist": [{
                "type": "2",
                "img": "@image(398x412,@color)",
                "title": "@ctitle(4,6)",
                "con": "@ctitle(4,8)"
            }, {
                "type": "0.5",
                "img": "@image(198x162,@color)",
                "title": "@ctitle(4,6)",
                "con": "@ctitle(4,8)"
            }, {
                "type": "0.5",
                "img": "@image(198x162,@color)",
                "title": "@ctitle(4,6)",
                "con": "@ctitle(4,8)"
            }, {
                "type": "0.5",
                "img": "@image(198x162,@color)",
                "title": "@ctitle(4,6)",
                "con": "@ctitle(4,8)"
            }, {
                "type": "0.5",
                "img": "@image(198x162,@color)",
                "title": "@ctitle(4,6)",
                "con": "@ctitle(4,8)"
            }, {
                "type": "1",
                "img": "@image(198x412,@color)",
                "title": "@ctitle(4,6)",
                "con": "@ctitle(4,8)"
            }]
        },
        //优质生活
        "youzhi": {
            "taglist|8-10": [{
                "text": "@ctitle(2,4)",
                "href": "#"
            }],
            "iconlist|15": [{
                "img": "@image(180x64,@color)",
                "href": "#"
            }],
            "collist|5": [{
                "type": "1",
                "img": "@image(198x412,@color)",
                "title": "@ctitle(4,6)",
                "con": "@ctitle(4,8)"
            }],
        },
        //团购
        "tuanlist|6": [{
            "href": "#",
            "img": "@image(590x280,@color)",
            "imgtext": "@ctitle(8,20)",
            "zhe|1-9": 1,
            "name": "@ctitle(6,12)",
            "day|1-20": 1,
        }]
    });
    index = new Vue({
        el: "#index",
        data() {
            return {
                typeList: '', //栏目标题
                bannerList: '', //轮播图
                barList: '', //头部导航
                headLeftList: '', //分类
                headimglist: '', //精选推荐
                hotpplist: '', //品牌列表
                tuanlist: '', //团购
                topParams: {
                    login: false,
                },
                hotpplistnum: 0, //热门品牌 被选中的位置数
                loginName: '',
                pinzhiD: "",
                pinzhiZ: "",
                pinzhiX: "",
                remen: "",
                youzhi: "",
                miaolist: null,
                categoryListRand: "",
                categoryListRandom: "",
                brandListRand: "",
                brandListRandom: "",
                activityState: null,
                activityStateTuan: null,
                miaoTime: [],
                tuanTime: []
            }
        },
        methods: {
            getData() {
                var that = this;
                let user = sessionStorage.getItem('user');
                let loginName = sessionStorage.getItem('loginName');
                if (user != null) {
                    this.topParams.login = true;
                    this.loginName = loginName;
                }
                //获取广告位
                axios({
                    method: 'get',
                    url: urlParam.domain() + '/api/ad/adListAllPC',
                    responseType: 'stream'
                }).then(function(response) {
                    var r = response.data.data;
                    that.typeList = r[0];
                    that.bannerList = r[0].list1; //头部滚动
                    that.barList = r[0].list8; //头部导航
                    that.youzhi = r[0].list7; //优质生活
                    that.pinzhiD = r[0].list6; //品质时尚-大图
                    that.pinzhiZ = r[0].list5; //品质时尚-中图
                    that.pinzhiX = r[0].list4; //品质时尚-小图
                    that.remen = r[0].list3; //热门品牌
                    that.headimglist = r[0].list2; //头部滚动-副图
                }).then(function() {
                    that.initSwipterBanner();
                });
                //获取分类
                axios({
                    method: 'get',
                    url: urlParam.domain() + '/api/category/categoryListPC',
                    responseType: 'stream',
                }).then(function(response) {
                    that.headLeftList = response.data.data;
                });
                //随机获取三级分类
                axios({
                    method: 'get',
                    url: urlParam.domain() + '/api/category/categoryListRandom?number=9',
                    responseType: 'stream',
                }).then(function(response) {
                    that.categoryListRand = response.data.data;
                });
                //随机获取三级分类
                axios({
                    method: 'get',
                    url: urlParam.domain() + '/api/category/categoryListRandom?number=9',
                    responseType: 'stream',
                }).then(function(response) {
                    that.categoryListRandom = response.data.data;
                });
                //随机获取品牌
                axios({
                    method: 'get',
                    url: urlParam.domain() + '/api/brand/brandListRandom?number=15',
                    responseType: 'stream',
                }).then(function(response) {
                    that.brandListRand = response.data.data;
                }).then(function() {
                    that.initSwipterIcon();
                });
                //随机获取品牌
                axios({
                    method: 'get',
                    url: urlParam.domain() + '/api/brand/brandListRandom?number=15',
                    responseType: 'stream',
                }).then(function(response) {
                    that.brandListRandom = response.data.data;
                }).then(function() {
                    that.initSwipterIcon();
                });
                //获取热门品牌
                axios({
                    method: 'post',
                    url: urlParam.domain() + '/api/brand/brandSort',
                    responseType: 'stream'
                }).then(function(response) {
                    that.hotpplist = response.data.data;
                });
                //获取团购
                axios({
                    method: 'post',
                    url: urlParam.domain() + '/api/groupPurchasingActivity/groupPurchasingActivityList',
                    responseType: 'stream'
                }).then(function(response) {
                    that.tuanlist = response.data.data; //团购
                });
                //获取秒杀
                axios({
                    method: 'post',
                    url: urlParam.domain() + '/api/spikeActivity/spikeActivityList',
                    responseType: 'stream'
                }).then(function(response) {
                    that.miaolist = response.data.data; //秒杀
                });
                //this.headLeftList = mockData.headLeftList;
                //this.bannerList = mockData.bannerList; //轮播图
                //this.headimglist = mockData.headimglist;
                //this.hotimg = mockData.hotimg; //热门品牌
                //this.hotpplist = mockData.hotpplist; //热门品牌
                //this.miaolist = mockData.miaolist; //特价秒杀
                //this.pinzhi = mockData.pinzhi; //品质时尚
                //this.youzhi = mockData.youzhi; //优质生活
                //this.tuanlist = mockData.tuanlist; //团购
            },
            //将剩余秒数转换为天 时 分 秒格式
            countdown: function() {
                var that = this;
                setInterval(function() {
                    that.miaoTime = [];
                    for (let obj of that.miaolist) {
                        if (obj.startTime > 0) {
                            //未开始状态
                            obj.startTime--;
                            that.miaoTime.push(transformTimeleft(obj.startTime));
                            that.activityState = "距开始";
                        } else {
                            if (obj.startTime <= 0 && obj.endTime >= 0) {
                                //秒杀进行中
                                obj.endTime--;
                                that.miaoTime.push(transformTimeleft(obj.endTime));
                                that.activityState = "剩余";
                            } else {
                                //秒杀已结束
                                that.activityState = "已结束";
                            }
                        }
                    }
                    that.tuanTime = [];
                    for (let obj of that.tuanlist) {
                        if (obj.startTime > 0) {
                            //未开始状态
                            obj.startTime--;
                            that.tuanTime.push(transformTimeleft(obj.startTime));
                            that.activityStateTuan = "距开始";
                        } else {
                            if (obj.startTime <= 0 && obj.endTime >= 0) {
                                //秒杀进行中
                                obj.endTime--;
                                that.tuanTime.push(transformTimeleft(obj.endTime));
                                that.activityStateTuan = "剩余";
                            } else {
                                //秒杀已结束
                                that.activityStateTuan = "已结束";
                            }
                        }
                    }
                }, 1000)
            },
            initSwipterBanner() {
                var swiper = new Swiper('.swiper-container-banner', {
                    speed: 1000, //滑动速度，即slider自动滑动开始到结束的时间（单位ms），也是触摸滑动时释放至贴合的时间
                    autoplay: 4000, //可选选项，自动滑动
                    autoplayDisableOnInteraction: false, //用户操作swiper之后，是否禁止autoplay。默认为true：停止
                    loop: true, //让Swiper看起来是循环的。
                    effect: 'fade', //默认为" slide "（位移切换），可设置为" fade " 淡入 "  cube " 方块  " coverflow " 3d流  " flip " 3d翻转 。
                    //分页器
                    pagination: '.swiper-pagination', //设置分页器，默认null
                    paginationType: 'bullets', //分页器样式类型 ‘bullets’  圆点（默认）‘fraction’  分式  ‘progress’  进度条
                    paginationClickable: true, //点击分页器的指示点分页器会控制Swipe

                    lazyLoading: true, //设为true开启图片延迟加载
                    lazyLoadingInPrevNext: true, //设置为true允许将延迟加载应用到最接近的slide的图片（前一个和后一个slide）
                });
            },
            initSwipterIcon() {
                var swiper = new Swiper('.swiper-container-icon', {
                    speed: 3000, //滑动速度，即slider自动滑动开始到结束的时间（单位ms），也是触摸滑动时释放至贴合的时间
                    autoplay: 3000, //可选选项，自动滑动
                    autoplayDisableOnInteraction: false, //用户操作swiper之后，是否禁止autoplay。默认为true：停止
                    // loop: true, //让Swiper看起来是循环的。
                    //前进后退按钮
                    prevButton: '.swiper-button-prev',
                    nextButton: '.swiper-button-next',

                    slidesPerView: 1, //设置slider容器能够同时显示的slides数量
                    slidesPerColumn: 5, //多行布局里面每列的slide数量。
                    // loopAdditionalSlides: 5, //loop模式下会在slides前后复制若干个slide,，前后复制的个数不会大于原总个数。
                });
            },
            //点击热门品牌 切换显示
            hotpplistClick(index) {
                this.hotpplistnum = index;
            }
        },
        created() {
            this.getData();
            this.countdown();
        }
    });
}

//首页引导下进入的团购页
function indextuan() {
    let mockData = Mock.mock({
        "bannerList|6": [{
            "img": "@image('1920x360',@color)",
            "href": "#",
        }],
        "tuilist|4": [{
            "banner": "@image(285x366,@color)",
            "icon": "@image(180x46,@color)",
            "title": "@ctitle(6,8)",
            "con": "@ctitle(6,10)"
        }],
        //团购
        "tuanlist|10": [{
            "href": "#",
            "img": "@image(590x280,@color)",
            "imgtext": "@ctitle(8,20)",
            "zhe|1-9": 1,
            "name": "@ctitle(6,12)",
            "day|1-20": 1,
        }]
    });
    new Vue({
        el: "#indextuan",
        data() {
            return {
                topParams: {
                    login: false
                },
                topnavlist: {},
                tuanlist: null,
                activityStateTuan: null,
                tuanTime: [],
                tuanBannerList:null,
                tuijianList:null
            }
        },
        methods: {
            getData() {
                var that = this;
                this.bannerList = mockData.bannerList;
                this.tuilist = mockData.tuilist; //今日推荐

                //团购页面滚动图片
                axios({
                    method: 'get',
                    url: urlParam.domain() + '/api/ad/adOnePC?adPostionId=35',
                    responseType: 'stream'
                }).then(function(response) {
                    that.tuanBannerList = response.data.data.list;
                }).then(function() {
                    that.initSwipterBanner();
                });

                //今日推荐
                axios({
                    method: 'get',
                    url: urlParam.domain() + '/api/ad/adOnePC?adPostionId=36',
                    responseType: 'stream'
                }).then(function(response) {
                    that.tuijianList = response.data.data.list;
                });

                //获取团购
                axios({
                    method: 'post',
                    url: urlParam.domain() + '/api/groupPurchasingActivity/groupPurchasingActivityList',
                    responseType: 'stream'
                }).then(function(response) {
                    that.tuanlist = response.data.data; //团购
                });

            },
            //将剩余秒数转换为天 时 分 秒格式
            countdown: function() {
                var that = this;
                setInterval(function() {
                    that.tuanTime = [];
                    for (let obj of that.tuanlist) {
                        if (obj.startTime > 0) {
                            //未开始状态
                            obj.startTime--;
                            that.tuanTime.push(transformTimeleft(obj.startTime));
                            that.activityStateTuan = "距开始";
                        } else {
                            if (obj.startTime <= 0 && obj.endTime >= 0) {
                                //秒杀进行中
                                obj.endTime--;
                                that.tuanTime.push(transformTimeleft(obj.endTime));
                                that.activityStateTuan = "剩余";
                            } else {
                                //秒杀已结束
                                that.activityStateTuan = "已结束";
                            }
                        }
                    }
                }, 1000)
            },
            initSwipterBanner() {
                var swiper = new Swiper('.indextuan_banner', {
                    speed: 1000, //滑动速度，即slider自动滑动开始到结束的时间（单位ms），也是触摸滑动时释放至贴合的时间
                    autoplay: 6000, //可选选项，自动滑动
                    autoplayDisableOnInteraction: false, //用户操作swiper之后，是否禁止autoplay。默认为true：停止
                    loop: true, //让Swiper看起来是循环的。
                    effect: 'fade', //默认为" slide "（位移切换），可设置为" fade " 淡入 "  cube " 方块  " coverflow " 3d流  " flip " 3d翻转 。
                    //分页器
                    pagination: '.swiper-pagination', //设置分页器，默认null
                    paginationType: 'bullets', //分页器样式类型 ‘bullets’  圆点（默认）‘fraction’  分式  ‘progress’  进度条
                    paginationClickable: true, //点击分页器的指示点分页器会控制Swipe

                    lazyLoading: true, //设为true开启图片延迟加载
                    lazyLoadingInPrevNext: true, //设置为true允许将延迟加载应用到最接近的slide的图片（前一个和后一个slide）
                });
            },
        },
        created() {
            this.getData();
            this.countdown();
        },
        mounted() {
            this.initSwipterBanner();
        },
        components: {

        }
    });
}

//促销活动
function indexcuxiao() {
    let mockData = Mock.mock({
        "topbanner": "@image(1920x450,@color)",
        "couponlist|3": [{
            "price|5-99": 1,
            "man": "99",
            "begin": "2017.12.10",
            "end": "12.30"
        }],
        "conlist|2": [{
            "title": "@ctitle(5,10)",
            "goodslist|8": [{
                "img": "@image(285x366,@color)",
                "href": "#",
                "price": "100-900.2",
                "text": "@ctitle(8,15)"
            }]
        }],
    });
    new Vue({
        el: "#indexcuxiao",
        data() {
            return {
                topParams: {
                    login: true,
                },
                topnavlist: {},
            }
        },
        methods: {
            getData() {
                this.topbanner = mockData.topbanner; //顶部通栏banner
                this.couponlist = mockData.couponlist; //优惠券
                this.conlist = mockData.conlist; //促销内容
            },
        },
        created() {
            this.getData();
        },
        mounted() {

        },
        components: {

        }
    });
}

//优质生活
function indexyou() {
    let mockData = Mock.mock({
        // "crumblist|4-6": [{
        //     "text": "@ctitle(4,18)",
        //     "href": "#"
        // }],
        "prolist|8": [{
            'img': "@image('214x274',#eac7ce)",
            'title': "@ctitle(5, 10)",
            'sellprice|100-200.2': 239.00,
            'manjian|0-1': 0,
            'baoyou|0-1': 0
        }],
        "catelist": ['休闲日常', '秋冬新品', '母婴专场', '职场丽人', '红人穿搭']
    });
    new Vue({
        el: "#indexyou",
        data() {
            return {
                topParams: {
                    login: true,
                },
                topnavlist: {},
                prolist: null,
                catelist: null,
            }
        },
        methods: {
            getData() {
                this.crumblist = [{
                    "text": "首页",
                    "href": "#"
                },
                    {
                        "text": "优质生活",
                        "href": "#"
                    }
                ];
                this.prolist = mockData.prolist;
                this.catelist = mockData.catelist;
            },
            listen: function(data) {
                // 翻页事件
                alert('当前页码：' + data);
            }
        },
        created() {
            this.getData();
        },
        mounted() {

        },
        components: {
            'pro-list': base_product_list,
            'cate-type': cate_type,
            'paixu': paixu
        }
    });
}